package com.cisetech.web.bobocai.houtai;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import com.cisetech.service.IndexServic;
import com.cisetech.util.FileOperateUtil;
import com.cisetech.vo.bobocai.TitleVo;

//首页内容控制器
@Controller
@RequestMapping(value="/index")
public class IndexController {
	@Autowired
	IndexServic indexServic;
	
	
	@RequestMapping(value="",method=RequestMethod.GET)
	public ModelAndView index(HttpServletResponse response,HttpServletRequest request){
		ModelAndView v = new ModelAndView("houtai/index");
		return v;
	}
	
	
	//logo图
	@ResponseBody
	@RequestMapping(value="/image",method=RequestMethod.POST)
	public String image(@RequestParam(value = "image" ,required = false) MultipartFile[] image,
    		HttpServletRequest request,HttpServletResponse response){
		String img="";
		if (image != null && image.length > 0) {
            for (int i = 0; i < image.length; i++) {
                MultipartFile file = image[i];
                // 保存文件
                String filePath = request.getSession().getServletContext().getRealPath("/") + "WEB-INF/upload/img/logo.jpg";
                img = FileOperateUtil.saveFiles(file,"logo",filePath); 
            }
        }

		return img;
	}
	
	//接收保存网站的基本信息
	@ResponseBody
	@RequestMapping(value="/indexHead",method=RequestMethod.POST)
	public String indexHead(TitleVo titleVo,HttpServletRequest request,HttpServletResponse response){
		String s = indexServic.indexHead(titleVo);
		return s;
	}
}
